package br.com.controlefinanceiro.negocio;

import java.util.Date;
import java.util.List;

import javax.faces.bean.NoneScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;

import br.com.controlefinanceiro.entidade.Evento;
import br.com.controlefinanceiro.integracao.EMF;

@NoneScoped
@Named
public class EventoService {

	@Inject
	private EMF emf;
	
	public void incluirEvento() {
		EntityManager entityManager = emf.getEmf().createEntityManager();
		Evento evento = new Evento();
		evento.setData(new Date());
		evento.setDescricao("Teste");
		entityManager.persist(evento);
		entityManager.close();

	}

	@SuppressWarnings("unchecked")
	public List<Evento> getListaEventos() {
		EntityManager entityManager = null;
		try {
			entityManager = emf.getEmf().createEntityManager();
			return entityManager
					.createQuery("select evento from Evento evento")
					.getResultList();
		} finally {
			if(entityManager!=null){
			entityManager.close();
			}
		}
	}


}
